﻿<%!	
	public Message examine(Input input) {
		Message msg = new Message();
		Integer hospital = input.getInt("hospital");
		String sampleNo = input.getDesc("sample_no", "-1");
		String patientId = input.getDesc("patient_id", "-1");
		String hql = "from Examine where hospital=" + hospital + " and status=" + STATUS_ENABLE;
		if (!"-1".equals(sampleNo)) {
			hql = hql + " and sampleNo = '" + sampleNo + "'";
		} else {
			hql = hql + " and patientId = '" + patientId + "'";
		}
		List<Examine> list = QBuilder.db("basedb").queryHql(hql);
		if (list.size() == 0 ) {
			setErrcode(msg, NO_RESULT);
			return msg;
		}
		Examine em = list.get(0);
		Map<String, String> util = new HashMap<String, String> ();
		util.put("patient_id", Tools.getDesc(em.getPatientId(), ""));
		util.put("patient_name", Tools.getDesc(em.getPatientName(), ""));
		util.put("sample_no", Tools.getDesc(em.getSampleNo(), ""));
		List resList = new ArrayList();
		Map<String, String> keyMap = new HashMap<String, String> ();
		for (Examine examine:list) {
			keyMap.put(Tools.getDesc(examine.getParentItemId()), Tools.getDesc(examine.getParentItemName()));
		}
		Set<String> set = keyMap.keySet();
		for (String key:set) {
			Map<String, Object> result = new HashMap<String, Object> ();
			result.put("item_id", key);
			result.put("item_name", keyMap.get(key));
			List itemList = new ArrayList();
			for (Examine examine:list) {
				Map<String, String> map = new HashMap<String, String>();
				map.put("item_name", Tools.getDesc(examine.getItemName(), ""));
				map.put("item_unit", Tools.getDesc(examine.getItemUnit(), ""));
				map.put("description", Tools.getDesc(examine.getDescription(), ""));
				map.put("low_refer", Tools.getDesc(examine.getLowRefer(), ""));
				map.put("high_refer", Tools.getDesc(examine.getHighRefer(), ""));
				map.put("recieve_time", Tools.getDesc(examine.getReceiveTime(), ""));
				itemList.add(map);
			}
			result.put("items", itemList);
			resList.add(result);
		}
		msg.put("examine", resList);
		msg.put("util", util);
		return msg;
	}
%>